# coding: UTF-8
# Filename : get_pv_uv.py
# Company : imedia
# Author : rose
# -*-coding:utf-8 -*-
import sys,datetime
import os,commands

log_path = '/data/log/'

def getYesterday():   
    today=datetime.date.today()   
    oneday=datetime.timedelta(days=1)   
    yesterday=today-oneday   
    return yesterday

#日期设定
yesterday = getYesterday()
if len(sys.argv) >= 2:
    yesterday = sys.argv[1]
yesterday = str(yesterday)

print yesterday + ' pv，uv信息'

pv_shell = 'grep "" %saccess_log.%s -c' % (log_path, yesterday)
(a,b) = commands.getstatusoutput(pv_shell)
print 'pv:' + str(b)

uv_shell = '''grep "" %saccess_log.%s | awk -F '`' '{print $2 | "sort -u"}' | wc -l''' % (log_path, yesterday)
(a,b) = commands.getstatusoutput(uv_shell)
print 'uv:' + str(b)